package com._1.message.kafka;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class KafkaController {


    @Autowired
    KafkaProducerService kafkaProducerService;
    @PostMapping("/kafka/test")
    public void testKafka() throws InterruptedException {
        new Random().ints(1, 100).limit(1000).forEach(i -> {
            kafkaProducerService.sendMessage("test_2", "test_2_" + i);
        });
    }


    @PostMapping("/ka/testkaf2")
    public void testKafka2() throws InterruptedException {
        new Random().ints(1, 100).limit(10).forEach(i -> {
            kafkaProducerService.sendMessage("broadcast_topic", "test_2_" + i);
        });
    }

    @PostMapping("/kafka/test3")
    public void testKafka3() throws InterruptedException {
        new Random().ints(1, 100).limit(10).forEach(i -> {
            kafkaProducerService.sendMessage("random_topic", "test_2_" + i);
        });
    }
}
